﻿using NetworkLib.Utilities;
using System;
using System.Collections.Generic;
using System.Text;

namespace PokemonBattle
{
    public class DataByteArrayList<T> : DataByteArray where T : DataByteArray
    {
        public DataByteArrayList()
        {
            this.Elements = new List<T>();
        }

        public List<T> Elements { get; private set; }

        public override void Read(ByteArray byteArray)
        {
            int count = byteArray.ReadInt();
            this.Elements = new List<T>(count);
            for (int i = 0; i < count; i++)
            {
                var item = FromByteArray<T>(byteArray);
                this.Elements.Add(item);
            }
        }

        public override void Write(ByteArray byteArray)
        {
            byteArray.WriteInt(this.Elements.Count);
            foreach (T item in this.Elements)
            {
                item.Write(byteArray);
            }
        }
    }
}
